﻿using log4net;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using System.Windows.Forms;
using UpLoadDataOnTime.DataBaseUtil;
using UpLoadDataOnTime.Entity;
using UpLoadDataOnTime.Model;

namespace UpLoadDataOnTime
{
    public partial class UpLoadDataForm : Form
    {
        int hour, minute, second, flag = 0, minuteInterval;
        System.Timers.Timer timer = new System.Timers.Timer();
        private GetMZData GetMZData = new GetMZData();
        private GetZYData GetZYData = new GetZYData();
        ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public UpLoadDataForm()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        //打开数据实时上传测试页面
        private void UpDataTestMenuItem_Click(object sender, EventArgs e)
        {
            CheckInterfaceForm form = new CheckInterfaceForm();
            form.StartPosition = FormStartPosition.CenterParent;
            form.ShowDialog();
        }

        //执行任务
        private void StartButton_Click(object sender, EventArgs e)
        {
            timer.Enabled = true;
            if (TimingRadioButton.Checked)
            {
                log.Info(DateTime.Now.ToString() + "开启定时任务......");
                DateTimePicker.Enabled = false;
                DateTime dateTime = Convert.ToDateTime(DateTimePicker.Value.ToString());
                hour = int.Parse(dateTime.Hour.ToString());
                minute = int.Parse(dateTime.Minute.ToString());
                second = int.Parse(dateTime.Second.ToString());

                timer.Interval = 1000;//执行间隔时间,单位为毫秒  
                timer.Start();
                timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer1_Elapsed);
                OutPutRichTextBox.Clear();
                OutPutRichTextBox.AppendText("定时任务设定成功！设定时间为:" + hour.ToString() + "时" + minute.ToString() + "分" + second.ToString() + "秒" + "\n");

            }
            else
            {
                log.Info(DateTime.Now.ToString() + "开启间隔时间任务......");
                NumericUpDown.Enabled = false;
                OutPutRichTextBox.Clear();
                OutPutRichTextBox.AppendText("定时任务设定成功！设定间隔为:" + NumericUpDown.Value.ToString() + "时" + "\n");
                timer.Interval = 1000 * 3600 * int.Parse(NumericUpDown.Value.ToString());
                minuteInterval = 1000 * 3600 * int.Parse(NumericUpDown.Value.ToString());
                timer.Start();
                timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer1_Elapsed);
            }
        }

        private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (TimingRadioButton.Checked)
            {
                //得到intHour,intMinute,intSecond是当前系统时间  
                int intHour = e.SignalTime.Hour;
                int intMinute = e.SignalTime.Minute;
                int intSecond = e.SignalTime.Second;
                //自己设置hour,minuter,second,到设定的时间就开始执行程序  
                if (intHour == hour && intMinute == minute && intSecond == second)
                {
                    log.Info(DateTime.Now.ToString() + "开始执行上传任务");
                    DoTask(DateTime.Now.AddDays(-1).ToString(), DateTime.Now.ToString());
                    //SetText(DoTask("2017-01-01", "2017-01-10"));
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("时间到了！");
                DoTask(DateTime.Now.AddHours(-minuteInterval).ToString(),DateTime.Now.ToString());
            }
        }

        //依次执行实时数据上传函数
        private string DoTask(string BeginDate, string EndDate)
        {
            MZPatientInfo(BeginDate, EndDate);
            MZRegistInfo(BeginDate, EndDate);
            MZTreat(BeginDate, EndDate);
            MZPrescription(BeginDate, EndDate);
            MZDrugInfo(BeginDate, EndDate);
            MZOperation(BeginDate, EndDate);
            MZCheck(BeginDate, EndDate);
            MZLib(BeginDate, EndDate);
            MZResult(BeginDate, EndDate);
            ZYInfo(BeginDate, EndDate);
            ZYTbHospitalizationRecord(BeginDate, EndDate);
            ZYOutPatient(BeginDate, EndDate);
            ZYOperation(BeginDate, EndDate);
            ZYCheck(BeginDate, EndDate);
            ZYLib(BeginDate, EndDate);
            ZYResult(BeginDate, EndDate);

            return DateTime.Now.ToString() + "上传完成.";
        }

        //定时执行
        private void TimingRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (TimingRadioButton.Checked)
            {
                DateTimePicker.Enabled = true;
            }
            else
            {
                DateTimePicker.Enabled = false;
            }
        }

        //门诊患者基本信息
        public void MZPatientInfo(string BeginDate, string EndDate)
        {
            //获取数据(请求使用了RestSharp库)
            try
            {
                List<MZPatientInfo> list = GetMZData.getMZPatientInfo(BeginDate, EndDate);
                foreach (MZPatientInfo patient in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = " 门诊患者基本信息上传: ID号:" + patient.grbsh + " 姓名:" + patient.xm;
                    //上传数据
                    WebPost("saveMZTbPatientInfo", JsonConvert.SerializeObject(patient), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊患者基本信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊患者基本信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //门诊挂号信息
        public void MZRegistInfo(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbResistration> list = GetMZData.GetMZTbResistrations(BeginDate, EndDate);
                foreach (MZTbResistration mz in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊挂号信息上传: ID号:" + mz.grbsh + " 时间:" + mz.gthsj;
                    WebPost("saveMZTbResistration", JsonConvert.SerializeObject(mz), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊挂号信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊挂号信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //门诊就诊信息
        public void MZTreat(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbClinicRecord> list = GetMZData.GetMZTbClinicRecords(BeginDate, EndDate);
                foreach (MZTbClinicRecord record in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊就诊信息上传: " + "ID号:" + record.grbsh + "日期:" + record.jzksrq;
                    WebPost("saveMZTbClinicRecord", JsonConvert.SerializeObject(record), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊就诊信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊就诊信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //门诊处方信息
        public void MZPrescription(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbRecipe> list = GetMZData.GetMZTbRecipes(BeginDate, EndDate);
                foreach (MZTbRecipe recipe in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊处方信息上传: " + "ID号:" + recipe.grbsh + "门诊号:" + recipe.jzlsh;
                    WebPost("saveMZTbRecipe", JsonConvert.SerializeObject(recipe), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊处方信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊处方信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }

        }

        //门诊处方药品信息
        public void MZDrugInfo(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbMedicine> list = GetMZData.GetMZTbMedicines(BeginDate, EndDate);
                foreach (MZTbMedicine medici in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊处方药品信息上传： ID号:" + medici.grbsh + " 处方主ID:" + medici.cfzid;
                    WebPost("saveMZTbMedicine", JsonConvert.SerializeObject(medici), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊处方药品信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊处方药品信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //门诊手术信息
        public void MZOperation(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbOperation> list = GetMZData.GetMZTbOperations(BeginDate, EndDate);
                foreach (MZTbOperation operation in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊手术信息上传: ID号:" + operation.grbsh + " 就诊流水号:" + operation.jzlsh;
                    WebPost("saveMZTbOperation", JsonConvert.SerializeObject(operation), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊手术信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊手术信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //门诊检查信息
        public void MZCheck(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbCheckRecord> list = GetMZData.GetMZTbCheckRecords(BeginDate, EndDate);
                foreach (MZTbCheckRecord check in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊检查信息: ID号:" + check.grbsh + " 就诊流水号:" + check.jzlsh;
                    WebPost("saveMZTbCheckRecord", JsonConvert.SerializeObject(check), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊检查信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊检查信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //门诊检验信息
        public void MZLib(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbAssayRecord> list = GetMZData.GetMZTbAssayRecords(BeginDate, EndDate);
                foreach (MZTbAssayRecord record in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊检验信息: ID号:" + record.grbsh + " 就诊流水号:" + record.jzlsh;
                    WebPost("saveMZTbAssayRecord", JsonConvert.SerializeObject(record), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊检查信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊检查信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //门诊检验结果指标信息
        public void MZResult(string BeginDate, string EndDate)
        {
            try
            {
                List<MZTbAssayQuotaResult> list = GetMZData.GetMZTbAssayQuotaResults(BeginDate, EndDate);
                foreach (MZTbAssayQuotaResult result in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "门诊检验结果指标信息: ID号" + result.jybgid + " 日期:" + result.bgrq;
                    WebPost("saveMZTbAssayQuotaResult", JsonConvert.SerializeObject(result), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 门诊检验结果指标信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 门诊检验结果指标信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //住院患者基本信息
        public void ZYInfo(string BeginDate, string EndDate)
        {
            try
            {
                List<ZYTbPatientInfo> list = GetZYData.GetZYTbPatientInfos(BeginDate, EndDate);
                foreach (ZYTbPatientInfo info in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "ID号:" + info.grbsh + " 姓名:" + info.xm;
                    WebPost("saveZYTbPatientInfo", JsonConvert.SerializeObject(info), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 住院患者基本信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 住院患者基本信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //住院记录信息
        public void ZYTbHospitalizationRecord(string BeginDate, string EndDate)
        {
            try
            {
                List<ZYTbHospitalizationRecord> list = GetZYData.GetZYTbHospitalizationRecords(BeginDate, EndDate);
                foreach (ZYTbHospitalizationRecord record in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "ID号:" + record.grbsh + " 住院号:" + record.jzlsh;
                    WebPost("saveZYTbPatientInfo", JsonConvert.SerializeObject(record), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 住院记录信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 住院记录信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //出院小结信息
        public void ZYOutPatient(string BeginDate, string EndDate)
        {
            try
            {
                List<ZYTbDischargeAbstract> list = GetZYData.GetZYTbDischargeAbstracts(BeginDate, EndDate);
                foreach (ZYTbDischargeAbstract abs in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "ID号:" + abs.grbsh + " 住院号:" + abs.jzlsh;
                    WebPost("saveZYTbDischargeAbstract", JsonConvert.SerializeObject(abs), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 出院小结信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 出院小结信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //住院手术信息
        public void ZYOperation(string BeginDate, string EndDate)
        {
            try
            {
                List<ZYTbOperation> list = GetZYData.GetZYTbOperations(BeginDate, EndDate);
                foreach (ZYTbOperation operation in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "ID号:" + operation.grbsh + " 住院号:" + operation.jzlsh;
                    WebPost("saveZYTbOperation", JsonConvert.SerializeObject(operation), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 住院手术信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 住院手术信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //住院检查信息
        public void ZYCheck(string BeginDate, string EndDate)
        {
            try
            {
                List<ZYTbCheckRecord> list = GetZYData.GetZYTbCheckRecords(BeginDate, EndDate);
                foreach (ZYTbCheckRecord record in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "ID号:" + record.grbsh + " 住院号:" + record.jzlsh;
                    WebPost("saveZYTbCheckRecord", JsonConvert.SerializeObject(record), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 住院检查信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 住院检查信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //住院检验信息
        public void ZYLib(string BeginDate, string EndDate)
        {
            try
            {
                List<ZYTbAssayRecord> list = GetZYData.GetZYTbAssayRecords(BeginDate, EndDate);
                foreach (ZYTbAssayRecord record in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "ID号:" + record.grbsh + " 住院号:" + record.jzlsh;
                    WebPost("saveZYTbAssayRecord", JsonConvert.SerializeObject(record), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 住院检验信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 住院检验信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //住院检验结果指标信息
        public void ZYResult(string BeginDate, string EndDate)
        {
            try
            {
                List<ZYTbAssayQuotaResult> list = GetZYData.GetZYTbAssayQuotaResults(BeginDate, EndDate);
                foreach (ZYTbAssayQuotaResult result in list)
                {
                    if (flag == 1)
                    {
                        break;
                    }
                    string temp = "检验报告ID:" + result.jybgid + " 日期:" + result.bgrq;
                    WebPost("saveZYTbAssayQuotaResult", JsonConvert.SerializeObject(result), temp);
                    SetText(temp);
                }
            }
            catch (NullReferenceException)
            {
                log.Warn(DateTime.Now.ToString() + " 住院检验结果指标信息 " + BeginDate + " - " + EndDate + " 未查询出数据");
                SetText(DateTime.Now.ToString() + " 住院检验结果指标信息 " + BeginDate + " - " + EndDate + " 未查询出数据 \n");
            }
            if (flag == 1)
            {
                SetText("门诊患者基本信息上传停止................................ \n");
            }
            else
            {
                SetText("门诊患者基本信息上传完毕................................ \n");
            }
        }

        //数据上传网络请求
        public void WebPost(string RequestMethodName, string json, string LogStr)
        {
            //上传数据
            string url = ConfigurationManager.ConnectionStrings["url"].ConnectionString;
            RestClient client = new RestClient(url);
            //参数1为服务名称
            RestRequest request = new RestRequest(RequestMethodName, Method.POST);
            request.AddHeader("accessAccount", ConfigurationManager.AppSettings["accessAccount"]);
            request.AddHeader("sig", ConfigurationManager.AppSettings["sig"]);
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            //执行请求并返回结果
            IRestResponse response = client.Execute(request);
            if (response.IsSuccessful)
            {
                SetText(" ->" + response.Content + "\n");
                Response res = JsonConvert.DeserializeObject<Response>(response.Content);
                //写入一条新log
                if (res.code.Equals("0"))
                {
                    log.Info(DateTime.Now.ToString() + " " + RequestMethodName + " " + res.msg + LogStr);
                }
                else
                {
                    log.Warn(DateTime.Now.ToString() + " " + RequestMethodName + " " + res.msg + LogStr);
                }

            }
            else
            {
                log.Error(DateTime.Now.ToString() + " " + RequestMethodName + " " + "发送请求失败");
                SetText(" ->" + RequestMethodName + "发送请求失败" + "\n");
            }
        }

        //利用委托在主ui线程与定时执行线程之间设置控件的值
        private void SetText(string text)
        {
            //让文本框获取焦点 
            this.OutPutRichTextBox.Focus();
            //设置光标的位置到文本尾
            this.OutPutRichTextBox.Select(this.OutPutRichTextBox.TextLength, 0);
            //滚动到控件光标处
            this.OutPutRichTextBox.ScrollToCaret();
            OutPutRichTextBox.AppendText(text);
        }

        //间隔执行
        private void IntervalRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (IntervalRadioButton.Checked)
            {
                NumericUpDown.Enabled = true;
            }
            else
            {
                NumericUpDown.Enabled = false;
            }
        }

        //停止任务
        private void StopButton_Click(object sender, EventArgs e)
        {
            timer.Stop();
            if (TimingRadioButton.Checked)
            {
                DateTimePicker.Enabled = true;
                log.Info(DateTime.Now.ToString() + "关闭定时任务......");
            }
            else
            {
                NumericUpDown.Enabled = true;
                log.Info(DateTime.Now.ToString() + "关闭间隔时间任务......");
            }
            OutPutRichTextBox.AppendText("定时任务已停止. \n");
            flag = 1;
        }
    }
}
